package com.achun.ximalayamvvm.view.adapter

import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager
import androidx.fragment.app.FragmentStatePagerAdapter
import androidx.fragment.app.FragmentStatePagerAdapter.BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT
import androidx.lifecycle.Lifecycle
import androidx.viewpager2.adapter.FragmentStateAdapter

class ViewPageAdapter(fm:FragmentManager,var lists: List<Fragment>):
    FragmentStatePagerAdapter(fm,BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT) {


    override fun getPageTitle(position: Int): CharSequence? {
        when(position){
            0-> return "推荐"
            1-> return "订阅"
            2-> return "历史"
            else ->return ""
        }
    }
    override fun getCount(): Int {
        return if (lists==null) 0 else lists.size;
    }

    override fun getItem(position: Int): Fragment {
      return lists[position]
    }
}